<template>
  <div class="medicalRecord-container">
    <!-- 就诊历史 -->
    <div class="medicalRecord-list-container">
      <div class="medicalRecord-title-container">
        <div class="title"><p class="title-con">就诊历史</p></div>
      </div>
      <div class="list-container">
        <ul class="list-ul" v-if="caseHistoryLists&&caseHistoryLists.length">
          <li
            class="list-item list-item-hover"
            v-for="(item, index) in caseHistoryLists"
            :key="index"
            @click="hisListClick(item.ID)"
            :class="[selectId == item.ID ? 'selectItem' : '']"
          >
            <div class="item-time">
              <span class="content">2021-01-29</span>
            </div>
            <div class="item-info">
              <span class="content">{{ item.medical_describe }}</span>
            </div>
            <div class="item-icon">
              <span class="content"
                ><i class="icon el-icon-arrow-right"></i
              ></span>
            </div>
          </li>
        </ul>
        <div class="data-null" v-else>
          <blank picWidth="120px"></blank>
        </div>
      </div>
    </div>
    <!-- 最近处方 -->
    <div class="medicalRecord-list-container">
      <div class="medicalRecord-title-container">
        <div class="title"><p class="title-con">最近处方</p></div>
      </div>
      <div class="list-container prescription-list-container">
        <div class="prescription-item-container" v-if="prescriptionList&&prescriptionList.length">
          <div
            class="prescription-container"
            v-for="(pers, pridx) in prescriptionList"
            :key="pridx"
          >
            <div class="list-title">
              <p>
                <span>{{ pers.category_name }}</span>
              </p>
            </div>
            <ul class="list-ul">
              <li class="list-item" v-for="(pro, ix) in pers.details" :key="ix">
                <div class="item-product">
                  <span class="content">{{ pro.product_name }}</span>
                </div>
                <div class="item-unit">
                  <span>{{ pro.number }}</span>
                  <span>{{ pro.unit }}</span>
                </div>
              </li>
            </ul>
          </div>
        </div>
        <div class="data-null" v-else>
          <blank picWidth="120px"></blank>
        </div>
      </div>
    </div>
    <!-- 检查治疗项 -->
    <div class="medicalRecord-list-container">
      <div class="medicalRecord-title-container">
        <div class="title"><p class="title-con">检查治疗项</p></div>
      </div>
      <div class="list-container check-item-container">
        <ul class="list-ul" v-if="checkItems&&checkItems.length">
          <li class="list-item" v-for="(check, idx) in checkItems" :key="idx">
            <div class="item-name">
              <span class="content">{{ check.check_item_name }}</span>
            </div>
            <div class="item-unit">
              <span class="content">{{ check.check_item_number }}</span>
              <span class="content">次</span>
            </div>
          </li>
        </ul>
        <div class="data-null" v-else>
          <blank picWidth="120px"></blank>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { historyListDetail, caseHistoryList } from "@/api/outpatient.js";
import blank from "../../../components/blank.vue";
export default {
  components: { blank },
  props: {
    resumeId: {
      type: Number,
      default: () => {},
    },
  },
  data() {
    return {
      caseHistoryLists: [],
      historyListPost: {
        resume_id: 0,
        pager: {
          number: 1,
          size: 5,
        },
      },
      selectId: 0,
      checkItems: [],
      prescriptionList: [],
    };
  },
  watch: {
    selectId: {
      handler(newval, oldval) {
        if (newval > 0) {
          this.getHistoryListDetail(newval);
        }
      },
    },
    resumeId: {
      handler(newval, oldval) {
        if (newval > 0) {
          this.historyListPost.resume_id = newval;
          this.getCaseHistoryList(this.historyListPost);
        } else {
          this.caseHistoryLists = [];
          this.checkItems = [];
          this.prescriptionList = [];
        }
      },
    },
  },
  created() {},
  methods: {
    hisListClick(id) {
      this.selectId = id;
    },
    getCaseHistoryList(data) {
      caseHistoryList(data).then((res) => {
        console.log(res.data.data || []);
        this.caseHistoryLists = res.data ? res.data.data : [];
        if (this.caseHistoryLists.length > 0) {
          this.selectId = this.caseHistoryLists[0].ID;
        }
      });
    },
    getHistoryListDetail(id) {
      historyListDetail(id).then((res) => {
        if (res.code == 200) {
          let datas = res.data;
          if (datas) {
            this.checkItems = datas ? datas.check_items : [];
            this.prescriptionList = datas.prescriptions;
          }
        }
      });
    },
  },
};
</script>

<style lang="scss">
@import "@/assets/scss/outpatient/modules/medicalRecord.scss";
</style>